class Solution {
public:  
    void dfs(Node* root, vector<int>& ans){
        if(!root) return;
        ans.push_back(root->val);
        for(auto &v: root->children)
            dfs(v,ans);
    }
    vector<int> preorder(Node* root) {
        vector<int> ans;
        dfs(root,ans);
        return ans;
    }
};